<?php
/**
 * @file phoneinfo.php $
 * @author LiangJian (liangjian@haibao.com) $
 * @date 2015年7月20日 下午5:09:32 $
 * @brief  $
 */
namespace haibao\app\data;

class PhoneInfo extends \haibao\app\data\Base{

    public function __construct(){
        parent::__construct('\haibao\app\model\data\PhoneInfo');
    }
    
	/**
	 * 添加新设备信息
	 * @param \haibao\app\model\data\PhoneInfo $model
	 */
    public function addPhoneInfo($model){
        $this->add($model);
    }
    
    public function getPhoneInfoByImei($iMei){
    	$sql = "select * from PhoneInfo where IMEI = %s";
    	$result = $this->query($sql,array($iMei));
    	$phoneInfoModel = null;
    	while($result->fetch_assoc()){
    		$phoneInfoModel = new \haibao\app\model\data\PhoneInfo();
    		$phoneInfoModel->IMEI = $result->getData('IMEI');
    		$phoneInfoModel->OSType = $result->getData('OSType');
    		$phoneInfoModel->OSVersion = $result->getData('OSVersion');
    	}
    	return $phoneInfoModel;
    }
    
    /**
     * 添加开启应用记录
     * @param \haibao\app\model\data\AppBootInfo $model
     */
    public function addAppBootInfo($model){
    	$this->setTableName($model);
    	$this->createAppBootInfoTable($model->getTableName());
    	$this->add($model);
    }
    
    /**
     * 添加返回的Token记录
     * @param \haibao\app\model\data\TokenInfo $model
     */
    public function addTokenInfo($model){
        $this->setTableName($model);
        $this->createTokenInfoTable($model->getTableName());
    	$this->add($model);
    }
    
    /**
     * 根据token获取app版本号
     */
    public function getAppVersionByToken($token){
        $tableName = 'TokenInfo_'.date('Ym');
        $result = $this->query('select AppVersion from '.$tableName.' where Token=%s', array($token));
        $appVersion = null;
        while($result->fetch_assoc()){
            $appVersion = $result->getData('AppVersion');
        }
        return $appVersion;
    }
    
    /**
     * 添加用户登录记录
     * @param \haibao\app\model\data\TokenInfo $model
     */
    public function addUserLoginHistory($model){
        $this->setTableName($model);
        $this->createUserLoginHistoryTable($model->getTableName());
    	$this->add($model);
    }
}
